package com.starinside.wp.repository.impl;

import com.starinside.wp.foundation.vo.WxParent;
import com.starinside.wp.repository.BaseNativeSqlRepository;
import com.starinside.wp.repository.WxParentRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class WxParentRepositoryImpl extends BaseNativeSqlRepository implements WxParentRepository {

    public WxParent findParentBy(String cid, String uid){

        String sql = "select u.id as parentUserId, u.name as parentName, c.id as childrenId, c.name as childrenName,  uc.relation as relation from users u\n" +
                "left join userchildren uc on uc.uid=u.id\n" +
                "left join children c on c.id =uc.cid\n" +
                "where uc.uid = '%s' and uc.cid='%s'";

        sql = String.format(sql, uid, cid);

        List<WxParent> result = sqlObjectList(sql, WxParent.class);

        return result.size() > 0? result.get(0): null;
    }

}
